package base.io;

import java.io.*;
import java.nio.file.Files;

public class InputStreamReaderAndWriter {
  private static String COMMON_PATH = "E:%stest%s";
  
  public static void main(String[] args) throws IOException {
    File inputFile = new File(String.format(COMMON_PATH + "reader.md", File.separator, File.separator));
    File outputFile = new File(String.format(COMMON_PATH + "writer01.md", File.separator, File.separator));
    
    InputStreamReader inputStreamReader = new InputStreamReader(Files.newInputStream(inputFile.toPath()));
    OutputStreamWriter outputStreamWriter = new OutputStreamWriter(Files.newOutputStream(outputFile.toPath()));
    
    char[] chars = new char[30];
    int readLength;
    while ((readLength = inputStreamReader.read(chars)) != -1) {
      System.out.println(String.valueOf(chars, 0, readLength));
      outputStreamWriter.write(chars, 0, readLength);
    }
    
    inputStreamReader.close();
    outputStreamWriter.close();
  }
}
